<?php
$username = $_POST['username'];
  $password = $_POST['password'];

  // 2. 验证
  // 2-1. 建立连接
  $link = mysqli_connect('localhost', 'root', 'root', 'shadouyou');

  // 2-2. 操作数据库查询
  $sql = "SELECT * FROM `users` WHERE `username`='$username' AND `password`='$password'";
  $res = mysqli_query($link, $sql);

  // 2-3. 解析结果
  $data = mysqli_fetch_all($res, MYSQLI_ASSOC);

  // 2-4. 关闭连接
  mysqli_close($link);
  if (count($data)) {
    // 表示有长度
    $arr = [
      "message" => "登录成功",
      "code" => 1,
      "info" => $data
    ];
  } else {
    // 表示没有长度
    $arr = [
      "message" => "登录失败",
      "code" => 0,
    ];
  }
  echo json_encode($arr);
?>